package top.juntower.controller;

import com.github.pagehelper.PageHelper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.juntower.pojo.EnjoyFoot;
import top.juntower.pojo.Carousel;
import top.juntower.pojo.FoodMatching;
import top.juntower.pojo.dto.FootDta;
import top.juntower.pojo.vo.RankingFootVo;
import top.juntower.service.impl.FirstPageServiceImpl;
import top.juntower.utils.JsonResult;

import java.util.List;

@Api(tags = "首页")
@RestController
@RequestMapping("firstpage")
public class FirstPageController {

    @Autowired
    FirstPageServiceImpl firstPageService;

    //首页轮播图
    @ApiOperation(value = "首页轮播图",response = EnjoyFoot.class)
    @GetMapping("/queryFirstPageLunBoTu")
    public JsonResult queryFirstPageLunBoTu(){

        List<Carousel> carousels = firstPageService.queryFirstPageLunBoTu();
        return  JsonResult.ok(carousels);
    }

    //精品推荐
    @ApiOperation(value = "精品推荐",response = EnjoyFoot.class)
    @GetMapping("/queryRecommendation")
    public JsonResult queryRecommendation(){
        List<RankingFootVo> rankingFootVos = firstPageService.queryRecommendation();
        return  JsonResult.ok(rankingFootVos);
    }

    //查询首页信息
    @ApiOperation(value = "查询首页信息",response = EnjoyFoot.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ftId", value = "类别Id", dataType = "Integer", required = true),
    })
    @GetMapping("/queryChineseFood")
    public JsonResult queryChineseFood(Integer ftId){
        if (ftId == null){
            return  JsonResult.ok(JsonResult.NO);
        }
        List<RankingFootVo> footDtas = firstPageService.queryChineseFood(ftId);
        return JsonResult.ok(footDtas);
    }

    //首页排行榜
    @ApiOperation(value = "首页排行榜",response = EnjoyFoot.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ftId", value = "类别Id", dataType = "Integer", required = true),
    })
    @GetMapping("/queryChineseFoodRanking")
    public JsonResult queryChineseFoodRanking(Integer ftId){
        if (ftId == null){
            return  JsonResult.ok(JsonResult.NO);
        }
        List<RankingFootVo> rankingFootVos = firstPageService.queryChineseFoodRanking(ftId);
        return JsonResult.ok(rankingFootVos);
    }

    //首页模糊搜索
    @ApiOperation(value = "首页模糊搜索",response = EnjoyFoot.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "footName", value = "食物名字", dataType = "String", required = true),
            @ApiImplicitParam(name = "pageNum", value = "分页页码", dataType = "Integer", required = true),
    })
    @GetMapping("/queryLikeFoot")
    public JsonResult queryLikeFoot(String footName,Integer pageNum){
        if (footName == null|| pageNum==null){
            return  JsonResult.ok(JsonResult.NO);
        }
        PageHelper.startPage(pageNum,20);
        List<FootDta> footDtas = firstPageService.queryLikeFoot(footName, pageNum, 20);
        if (footDtas == null){
            return JsonResult.error(JsonResult.MISS);
        }else {
            return  JsonResult.ok(footDtas);
        }
    }

    //首页食物搭配
    @ApiOperation(value = "首页食物搭配",response = EnjoyFoot.class)
    @GetMapping("/queryFoodMatchingRanking")
    public JsonResult queryFoodMatchingRanking(){
        List<FoodMatching> foodMatchings = firstPageService.queryFoodMatchingRanking();
        if (foodMatchings == null){
            return  JsonResult.error(JsonResult.MISS);
        }else {
            return  JsonResult.ok(foodMatchings);
        }
    }
}
